"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".

Replace this with more appropriate tests for your application.
"""

from django.test import TestCase
from backend.models import *
import MySQLdb

class SimpleTest(TestCase):
    def test_getAllCategory(self):
        rows = getAllCategory()
        print "----------------test_getAllCategory-------------------"
        if rows:
            for i in rows:
                print i
        else:
            print "Failed ! No Category Return"
            raise
        
    def test_getAllBook(self):
        rows = getAllBook()
        print "----------------test_getAllBook-------------------"
        if rows:
            for i in rows:
                print i
        else:
            print "Failed ! No Book Return"
            raise
        
    def test_getCategoryID(self):
        rows = getCategoryID()
        print "----------------test_getCategoryID-------------------"
        if rows:
            print rows
        else:
            print "Failed ! No thing from Category Return"
            raise
        
    def test_addNewCategory(self):
        print "----------------test_addNewCategory-------------------"
        addNewCategory("Professional book", "10", "0")
        db = initDataBase()
        cursor = db.cursor()
        sql = "select * from category as c where c.name = 'Professional book' " 
        cursor.execute(sql)
        rows = cursor.fetchall()
        if rows:
            print "OK"
        else:
            print "Failed ! Cannot Add New Category"
            raise
        db.close()
    def test_getAllUser(self):
        rows = getAllUser()
        print "----------------test_getAllUser-------------------"
        if rows:
            for i in rows:
                print i
        else:
            print "Failed ! No User Return"
            raise
        
    def test_getAllStatic(self):
        print "----------------test_getAllStatic-------------------"
        rows = getAllStatic()
        if rows:
            for i in rows:
                print i
        else:
            print "Failed ! No Static  Return"
            raise
    def test_getAllSetting(self):
        print "----------------test_getAllSetting-------------------"
        rows = getAllSetting()
        if rows:
            for i in rows:
                print i
        else:
            print "Failed ! No Setting  Return"
            raise
    